// Decompiled on 周六 2月 22 19:31:49 CST 2025 with Zomboid Decompiler v0.1.3 using Vineflower.
package zombie.randomizedWorld.randomizedBuilding;

import java.util.ArrayList;
import zombie.characters.IsoZombie;
import zombie.core.Rand;
import zombie.iso.BuildingDef;
import zombie.iso.IsoCell;
import zombie.iso.IsoGridSquare;
import zombie.iso.IsoWorld;
import zombie.iso.SpawnPoints;
import zombie.vehicles.BaseVehicle;

public final class RBBurntFireman extends RandomizedBuildingBase {
    @Override
    public void randomizeBuilding(BuildingDef def) {
        def.bAlarmed = false;
        int int0 = Rand.Next(1, 4);
        def.setHasBeenVisited(true);
        IsoCell isoCell = IsoWorld.instance.CurrentCell;

        for (int int1 = def.x - 1; int1 < def.x2 + 1; int1++) {
            for (int int2 = def.y - 1; int2 < def.y2 + 1; int2++) {
                for (int int3 = 0; int3 < 8; int3++) {
                    IsoGridSquare isoGridSquare = isoCell.getGridSquare(int1, int2, int3);
                    if (isoGridSquare != null && Rand.Next(100) < 70) {
                        isoGridSquare.Burn(false);
                    }
                }
            }
        }

        def.setAllExplored(true);
        ArrayList arrayList = this.addZombies(def, int0, "FiremanFullSuit", Integer.valueOf(35), this.getLivingRoomOrKitchen(def));

        for (int int4 = 0; int4 < arrayList.size(); int4++) {
            ((IsoZombie)arrayList.get(int4)).getInventory().setExplored(true);
        }

        BaseVehicle baseVehicle;
        if (Rand.NextBool(2)) {
            baseVehicle = this.spawnCarOnNearestNav("Base.PickUpVanLightsFire", def);
        } else {
            baseVehicle = this.spawnCarOnNearestNav("Base.PickUpTruckLightsFire", def);
        }

        if (baseVehicle != null) {
            baseVehicle.setAlarmed(false);
        }

        if (baseVehicle != null && !arrayList.isEmpty()) {
            ((IsoZombie)arrayList.get(Rand.Next(arrayList.size()))).addItemToSpawnAtDeath(baseVehicle.createVehicleKey());
        }
    }

    @Override
    public boolean isValid(BuildingDef buildingDef, boolean _boolean) {
        if (!super.isValid(buildingDef, _boolean)) {
            return false;
        } else {
            return buildingDef.getRooms().size() > 20 ? false : !SpawnPoints.instance.isSpawnBuilding(buildingDef);
        }
    }

    public RBBurntFireman() {
        this.name = "Burnt Fireman";
        this.setChance(2);
    }
}
